package org.xxpay.pay.channel.payeasepay.demo;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.xxpay.pay.channel.payeasepay.demo.CFCA.MerchantX509Cert;
import org.xxpay.pay.channel.payeasepay.util.XmlUtils;

import javax.ws.rs.core.MultivaluedMap;
import java.util.Map;
import java.util.Random;


public class Balance {
	
	private static final String SINGLE_CHECK_URL = "https://pay.yizhifubj.com/merchant/virement/mer_payment_balance_check.jsp";

	public static void main(String[] args) throws Exception {
		String XML = CheckCard(); //

		System.out.println("-----------------------------------------------------");
		System.out.println(XML);

		System.out.println(System.nanoTime());
		System.out.println((System.nanoTime()+"").substring(6) + (new Random().nextInt(100)+""));

	}

	

	public static String CheckCard() throws Exception {
		System.setProperty("https.protocols", "TLSv1.2,TLSv1.1,SSLv3");
		Client cc = Client.create();
		WebResource rr = cc.resource(SINGLE_CHECK_URL);

		MultivaluedMap queryParams = new MultivaluedMapImpl();
		
		String v_mid = "7606";

		/*String pfxFile = "D:/certificate/payease/19482_private.pfx";//
		String pfxPassword = "payN6886";
		String aliasPassword = "payN6886";
		String aliasName = "{ae87b4b1-262d-4005-8cdc-9b7530f7cc21}";*/
		//CFCAǩ��
		String pfxFile = "D:/certificate/payease/cfca_private.pfx";//
	    String pfxPassword = "lh121121";
	    String aliasPassword = "lh121121";
	    String aliasName = "{3dfcbb2d-bb3d-4350-9010-33de8cdb076c}";
	    String sign = MerchantX509Cert.sign(v_mid, pfxFile, aliasName, pfxPassword, aliasPassword);
		System.out.println(sign) ;
		System.out.println("--------------------------------------------------") ;
		queryParams.add("v_mid", v_mid);
		queryParams.add("v_mac", sign);
		String ret = rr.queryParams(queryParams).post(String.class);
		Map<String,String> resultMap = XmlUtils.xml2Map(ret);
		System.out.println(resultMap.get("status") + "_________" + resultMap.get("statusdesc") + "_________" + resultMap.get("balance") + "_________" + resultMap.get("sign"));
		return ret;
		
	}

}
